package com.offcn.controller;


import com.offcn.common.JsonController;
import com.offcn.pojo.Member;
import com.offcn.pojo.Role;
import com.offcn.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController extends JsonController {
    @Autowired
    MemberService memberService;


     /*
       需求：显示当前登录人员的姓名
       URL：http://localhost:80/eastCMS/user/get
       逻辑：
           1：接收请求
           2：将当前登录人员放到json域
     */

        @RequestMapping("get")
        @ResponseBody
        public Member get(HttpServletRequest request){
            HttpSession session = request.getSession();
            Member member = (Member) session.getAttribute("member");
            System.out.println("==========");
            System.out.println(member.getMname());
            return member;
        }
//    @RequestMapping("get")
//    public void get(HttpServletRequest request, HttpServletResponse response){
//        HttpSession session = request.getSession();
//        Member member = (Member) session.getAttribute("member");
//        JsonUtilObjecToJson(response,null,null,member);
//    }


      /*
       需求：查询当前登录人员的权限
       URL：http://localhost:80/eastCMS/user/getRole
       逻辑：
           1：接收请求
           2：查询当前登录人员
           3：根据登录人员的id 查询出role
           4：打包成json
     */

      @RequestMapping("getRole")
      @ResponseBody
        public Role getRole(HttpServletRequest request){
            Member sessionMember = (Member) request.getSession().getAttribute("member");
            Role role=memberService.selectRoleBySessionMember(sessionMember);
            return role;
        }

}
